package edu.tjpu.share.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.graphics.Bitmap;
import edu.tjpu.share.po.FileForDownload;
import edu.tjpu.share.po.UserVo;

public class ListMapUtil {
	public static List<Map<String, Object>> getUserListMap(List<UserVo> userList) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Iterator<UserVo> userIterator = userList.iterator();
		while (userIterator.hasNext()) {
			UserVo user = userIterator.next();
			Map<String, Object> map = new HashMap<String, Object>();
			// map.put("major", user.getMname());
			Bitmap bitmap = BitMapDrawableUtil.getBitmapFromByte(user
					.getUavatar());
			map.put("avatar", bitmap);
			map.put("check", false);
			map.put("uname", "用户名:" + user.getUname());
			// map.put("check", false);
			list.add(map);
		}
		return list;
	}

	public static List<Map<String, Object>> getFileListMap(
			List<FileForDownload> fileList) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		//SimpleDateFormat strDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Iterator<FileForDownload> fileIterator = fileList.iterator();
		while (fileIterator.hasNext()) {
			Map<String, Object> map = new HashMap<String, Object>();
			FileForDownload file = fileIterator.next();
			map.put("ficon", getFIcon(file.getFname()));
			
			map.put("fname", file.getFname());
			
			//map.put("date", strDate.format(file.getCdate()));
			map.put("date",TimeFormatUtil.getShortTime(file.getCdate()));
			
			map.put("msg", "留言：" + file.getMsg());
			
			map.put("unamefrom", "来自：" + file.getUnamefrom());
			list.add(map);
		}
		return list;

	}

	public static int getFIcon(String fname) {
		MIMEUtil mimeUtil = new MIMEUtil();
		String mimeType = mimeUtil.getMIMEType(fname);
		if (mimeType.contains("image/")) {
			return edu.tjpu.share.R.drawable.pictures;
		}
		else if (mimeType.contains("video/")) {
			return edu.tjpu.share.R.drawable.video;
		}
		else if (mimeType.contains("message/")) {
			return edu.tjpu.share.R.drawable.message;
		}
		else if (mimeType.contains("audio/")) {
			return edu.tjpu.share.R.drawable.music;
		}
		else if (mimeType.contains("application/")) {
			return edu.tjpu.share.R.drawable.application;
		}else {
			return edu.tjpu.share.R.drawable.file;
		}
		
	}
}
